package com.yyh.LIst1;

import java.util.LinkedList;
import java.util.List;

public class Test3 {
    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        System.out.println("list = " + list);
        list.add(2,"5");
        System.out.println("list = " + list);
        list.remove(2);
        System.out.println("list = " + list);
        list.set(1,"6");
        System.out.println("list = " + list);
        //将指定元素插入到列表的开头
        list.addFirst("7");
        System.out.println("list = " + list);
        //将指定元素插入到列表的末尾
        list.addLast("8");
        System.out.println("list = " + list);
        //获取但不删除列表的第一个元素
        System.out.println(list.getFirst());
        //获取但不删除列表的最后一个元素
        System.out.println(list.getLast());
        //将指定元素插入到列表的开头
        list.offerFirst("9");
        System.out.println("list = " + list);
    }
}
